<html>
<head><meta charset="utf-8"><title>not Send due to await retainment #67611 · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html">not Send due to await retainment #67611</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="184954386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184954386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184954386">(Jan 06 2020 at 20:44)</a>:</h4>
<p>hey <span class="user-mention" data-user-id="116118">@Matthew Jasper</span> are you around? I wanted to get your opinion on what steps we should take here</p>



<a name="184954563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184954563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184954563">(Jan 06 2020 at 20:46)</a>:</h4>
<p>I am. I wondered if there was any code that would hit this...</p>



<a name="184954686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184954686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184954686">(Jan 06 2020 at 20:48)</a>:</h4>
<p>I'm pretty sure this should not be considered a compiler bug. The following patch fixes the crate: <a href="https://gist.github.com/pnkfelix/4bdef50d0538fee8f6e0cbc4379f6074" target="_blank" title="https://gist.github.com/pnkfelix/4bdef50d0538fee8f6e0cbc4379f6074">https://gist.github.com/pnkfelix/4bdef50d0538fee8f6e0cbc4379f6074</a></p>



<a name="184954722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184954722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184954722">(Jan 06 2020 at 20:48)</a>:</h4>
<p>I was a little surprised that my first attempt of using <code>unsafe { &amp;PROXY[..] }</code> (i.e. just adding <code>[..]</code>) did not work. I had to actually <em>call</em> <code>.as_slice()</code>.</p>



<a name="184954857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184954857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184954857">(Jan 06 2020 at 20:50)</a>:</h4>
<p>is there anything analogous to <code>move ||</code>. but for generators? I.e. something that forces the generator to take a moved value rather than capturing a reference?</p>



<a name="184954890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184954890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184954890">(Jan 06 2020 at 20:50)</a>:</h4>
<p>(and my other question is whether we should consider trying to improve the diagnostics here or not)</p>



<a name="184955183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955183">(Jan 06 2020 at 20:53)</a>:</h4>
<p>Hmm. So I think that there are some possible fixes for this issue by make how we determine what a generator is holding across a yield a bit smarter, or by adjusting MIR lowering so that we don't ever hold on to the temporary pointer across a yield.</p>



<a name="184955191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955191">(Jan 06 2020 at 20:53)</a>:</h4>
<p><code>async move</code> should work</p>



<a name="184955333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955333">(Jan 06 2020 at 20:55)</a>:</h4>
<p>so you can do <code>async move fn foo(..) { ... }</code> ?</p>



<a name="184955384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955384">(Jan 06 2020 at 20:55)</a>:</h4>
<p>No, but the function's parameters are always captured by <code>move</code>.</p>



<a name="184955452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955452">(Jan 06 2020 at 20:56)</a>:</h4>
<p>But the statics aren't...</p>



<a name="184955464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955464">(Jan 06 2020 at 20:56)</a>:</h4>
<p>(that was the case I was thinking of)</p>



<a name="184955516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955516">(Jan 06 2020 at 20:57)</a>:</h4>
<p><code>static</code>s aren't captured</p>



<a name="184955710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955710">(Jan 06 2020 at 20:58)</a>:</h4>
<p>maybe I'm not using the right terminology</p>



<a name="184955760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955760">(Jan 06 2020 at 20:59)</a>:</h4>
<p>statics are handled by making unsafe  references to them, right?</p>



<a name="184955781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955781">(Jan 06 2020 at 20:59)</a>:</h4>
<p>that is at least how I interpreted what is happening here.</p>



<a name="184955791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955791">(Jan 06 2020 at 20:59)</a>:</h4>
<p>Yes</p>



<a name="184955946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955946">(Jan 06 2020 at 21:01)</a>:</h4>
<p>lets go back to the ideas you had for solutions.</p>



<a name="184955957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955957">(Jan 06 2020 at 21:01)</a>:</h4>
<blockquote>
<p>I was a little surprised that my first attempt of using <code>unsafe { &amp;PROXY[..] }</code> (i.e. just adding <code>[..]</code>) did not work. I had to actually <em>call</em> <code>.as_slice()</code>.</p>
</blockquote>
<p><code>region_scope_tree</code> being inferred based on the untyped HIR...</p>



<a name="184955978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184955978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184955978">(Jan 06 2020 at 21:01)</a>:</h4>
<p>hmm okay</p>



<a name="184956179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184956179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184956179">(Jan 06 2020 at 21:03)</a>:</h4>
<p>Anyway my instinct is that if we try to make the generator-transformation more complicated/subtle to handle cases like this, it could be frustrating for users trying to understand what their code is doing.</p>



<a name="184956236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184956236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184956236">(Jan 06 2020 at 21:04)</a>:</h4>
<p>but maybe I'm being paranoid</p>



<a name="184956273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184956273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184956273">(Jan 06 2020 at 21:04)</a>:</h4>
<p>So, the reason I think that we can fix this is that the pointer the we create is usually very short lived, it only rarely needs to be captured across a yield.</p>



<a name="184956475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184956475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184956475">(Jan 06 2020 at 21:06)</a>:</h4>
<p>But I don't think that HIR typeck really gives us a way to do anything other that what we currently have, or requiring that it's <em>never</em> live across a yield.</p>



<a name="184956937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184956937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184956937">(Jan 06 2020 at 21:11)</a>:</h4>
<p>Well, maybe the <code>&amp;PROXY[..]</code> vs. <code>PROXY.as_slice()</code> thing.</p>



<a name="184960378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/184960378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#184960378">(Jan 06 2020 at 21:48)</a>:</h4>
<p>I guess the right thing at this point is to let the Async-Await WG decide how to handle this?</p>



<a name="185605827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/185605827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#185605827">(Jan 14 2020 at 15:23)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> do you plan to invest more time in near term investigating the solution here? I'm just trying to figure out whether I should post a PR to "fix" to the <code>updns</code> crate that was broken by this.</p>



<a name="185628211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/185628211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#185628211">(Jan 14 2020 at 19:05)</a>:</h4>
<p>I'm waiting for feedback to the write up I did.</p>



<a name="185643947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/185643947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#185643947">(Jan 14 2020 at 21:47)</a>:</h4>
<p>...were there questions in that write up? It was an overview of a couple different trajectories we might take, right?</p>



<a name="185644225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/185644225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#185644225">(Jan 14 2020 at 21:50)</a>:</h4>
<p>Yes, the question is whether we think any of them are with working on.</p>



<a name="185645432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/not%20Send%20due%20to%20await%20retainment%20%2367611/near/185645432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/not.20Send.20due.20to.20await.20retainment.20.2367611.html#185645432">(Jan 14 2020 at 22:02)</a>:</h4>
<p>gotcha okay. I'll have to review more carefully. To be honest I wasn't clear about the drawbacks of the MIR internal local approach, but maybe that's because I wasn't clear about the details of that approach in general.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>